package com.qingzhuge.member.service.impl;

import com.qingzhuge.exception.ValidatorException;
import com.qingzhuge.member.dao.SysThirdAppConfigDao;
import com.qingzhuge.member.entity.SysThirdAppConfig;
import com.qingzhuge.member.service.ISysThirdAppConfigService;
import com.qingzhuge.service.BasePkLongServiceImpl;
import org.apache.commons.lang3.StringUtils;
import org.springframework.cache.annotation.CacheConfig;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import static com.qingzhuge.member.service.impl.SysThirdAppConfigServiceImpl.CACHE_NAME;

/**
 * @author : zero.xiao
 * @description :  第三方登录
 * @date :2018/10/16 0016 下午 20:25
 * @since : 1.0.0
 * @modified :
 */
@Service
@CacheConfig(cacheNames = CACHE_NAME)
public class SysThirdAppConfigServiceImpl extends BasePkLongServiceImpl<SysThirdAppConfigDao, SysThirdAppConfig> implements ISysThirdAppConfigService {
    static final String CACHE_NAME = "thirdAppConfigService";
    @Override
    @Cacheable(condition = "#appId != null", key = "#appId")
    public SysThirdAppConfig findByAppId(String appId) {
        if (StringUtils.isEmpty(appId)){
            throw new ValidatorException();
        }
        SysThirdAppConfig thirdAppConfig = baseDao.findByAppId(appId);
        if (thirdAppConfig == null) {
            throw new ValidatorException("服务器没有配置小程序信息");
        }
        return thirdAppConfig;
    }
}
